package com.mz.ieann.aide.base.vb

import androidx.annotation.LayoutRes
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.viewbinding.ViewBinding
import com.mz.ieann.aide.base.BaseFragment
import java.lang.reflect.ParameterizedType

/**
 * <p>------------------------------------------------------
 * <p> Copyright (C) 2021 zhangmz, All rights reserved.
 * <p> If there is technical discussion, you can contact zhangmz90@foxmail.com
 * <p>------------------------------------------------------
 * <p> viewModel+viewBinding
 * <p>
 *
 * @author Created by zhangmz
 * @date on 2021/12/5
 */
open class BaseVBFragment<VM : ViewModel>(@LayoutRes val resId: Int) : BaseFragment(resId) {

    /**
     * 可调用的 ViewModel
     */
    protected val viewModel: VM by lazy {
        val vmClass = (this.javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<VM>
        ViewModelProvider(this)[vmClass]
    }

    inline fun <reified VB : ViewBinding> bindView() = ViewBindingAchieve(VB::class.java)

}